package com.czxy.mapper;

import com.czxy.pojo.TUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

/**
 * @author likk
 * @create 2018/9/5
 */
@Repository
public interface UserMapper extends Mapper<TUser> {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from t_user where username = #{username} and status = 1")
    @Results(id = "userResultMap", value = {
            @Result(property = "subject", column = "subject_id", one = @One(select = "com.czxy.mapper.SubjectMapper.selectByPrimaryKey")),
            @Result(property = "grade", column = "grade_id", one = @One(select = "com.czxy.mapper.GradeMapper.selectByPrimaryKey")),
            @Result(property = "tclass", column = "class_id", one = @One(select = "com.czxy.mapper.ClassMapper.selectByPrimaryKey")),
            @Result(property = "level", column = "level_id", one = @One(select = "com.czxy.mapper.LevelMapper.selectByPrimaryKey"))
    })
    public TUser findByUsername(@Param("username") String username);

    /**
     * 根据学生姓名查询学生信息
     * @param name
     * @return
     */
    @Select("select * from t_user where name = #{name} and status = 1")
    @ResultMap(value = "userResultMap")
    public TUser findByName(@Param("name") String name);
}
